<template>
    <div class="app-container">
      <div class="block">
        <el-row  :gutter="24">

          <el-col :span="4">
            <el-select v-model="listQuery.communityId" placeholder="选择社区" @change="getCustsSearch">
              <el-option
                v-for="item in options.communityIds"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="4">
            <el-select v-model="listQuery.quoteType" placeholder="选择报价类型">
              <el-option
                v-for="item in options.quoteType"
                :key="item.k"
                :label="item.v"
                :value="item.k">
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="8">
            <el-button type="success" icon="el-icon-search" @click.native="search">{{ $t('button.search') }}</el-button>
            <el-button type="primary" icon="el-icon-refresh" @click.native="reset">{{ $t('button.reset') }}</el-button>
          </el-col>
        </el-row>
        <br>
      </div>


        <div class="block">
            <el-row>
                <el-col :span="24">
                    <el-button type="success" icon="el-icon-plus" @click.native="add">{{ $t('button.add') }}</el-button>
                    <el-button type="primary" icon="el-icon-edit" @click.native="edit">{{ $t('button.edit') }}</el-button>
                    <el-button type="danger" icon="el-icon-delete" @click.native="remove">{{ $t('button.delete') }}</el-button>
                </el-col>
            </el-row>
        </div>


        <el-table :data="list" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row
                  @current-change="handleCurrentChange">
            <el-table-column label="序号" type="index" show-overflow-tooltip width="50" align="center">
            </el-table-column>
            <el-table-column label="社区">
                <template slot-scope="scope">
                    {{scope.row.communityName}}
                </template>
            </el-table-column>
            <el-table-column label="报价类型" align="center">
                <template slot-scope="scope">
                  <span style="color:blue;" v-if="scope.row.quoteType===1">{{scope.row.quoteTypeName}}</span>
                  <span style="color:red;" v-if="scope.row.quoteType===2">{{scope.row.quoteTypeName}}</span>
                </template>
            </el-table-column>
            <el-table-column label="报价周期" align="center">
                <template slot-scope="scope">
                    {{scope.row.quoteRange}}
                </template>
            </el-table-column>
            <el-table-column label="报价周期单位" align="center">
                <template slot-scope="scope">
                    {{scope.row.quoteUnitName}}
                </template>
            </el-table-column>
            <el-table-column label="报价" align="center">
                <template slot-scope="scope">
                    {{scope.row.quotePrice}} 元
                </template>
            </el-table-column>
        </el-table>

        <el-pagination
                background
                layout="total, sizes, prev, pager, next, jumper"
                :page-sizes="[10, 20, 50, 100,500]"
                :page-size="listQuery.limit"
                :total="total"
                @size-change="changeSize"
                @current-change="fetchPage"
                @prev-click="fetchPrev"
                @next-click="fetchNext">
        </el-pagination>

        <el-dialog
                :title="formTitle"
                :visible.sync="formVisible"
                width="70%">
            <el-form ref="form" :model="form" :rules="rules" label-width="150px">
                <el-row>
                    <el-col :span="12">
                      <el-form-item label="社区" prop="communityId">
                        <el-select v-model="form.communityId" placeholder="请选择" @change="getBuildings">
                          <el-option
                            v-for="item in options.communityIds"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="报价类型" prop="quoteType" >
                            <el-select v-model="form.quoteType" placeholder="请选择">
                              <el-option
                                v-for="item in options.quoteType"
                                :key="item.k"
                                :label="item.v"
                                :value="item.k">
                              </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="报价周期" prop="quoteRange" >
                            <el-input v-model.number="form.quoteRange" minlength=1></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="报价周期单位" prop="quoteUnit">
                            <el-select v-model="form.quoteUnit" placeholder="请选择">
                              <el-option
                                v-for="item in options.quoteUnit"
                                :key="item.k"
                                :label="item.v"
                                :value="item.k">
                              </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="报价" prop="quotePrice" >
                            <el-input v-model.number="form.quotePrice" minlength=1>
                              <template slot="append">元</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item>
                    <el-button type="primary" @click="save">{{ $t('button.submit') }}</el-button>
                    <el-button @click.native="formVisible = false">{{ $t('button.cancel') }}</el-button>
                </el-form-item>

            </el-form>
        </el-dialog>
    </div>
</template>

<script src="./parking_quote.js"></script>


<style rel="stylesheet/scss" lang="scss" scoped>
    @import "src/styles/common.scss";
</style>

